package leetcode.hash;

/**
 * @author mazouri
 * @create 2021-09-27 23:14
 */
public class _477_totalHammingDistance {
    public int totalHammingDistance(int[] nums) {
        int sum = 0;
        for (int i = 0; i < nums.length; i++) {
            for (int j = i + 1; j < nums.length; j++) {
                sum += getHammingDistance(nums[i], nums[j]);
            }
        }
        return sum;
    }

    private int getHammingDistance(int num1, int num2) {
        return Integer.bitCount(num1^num2);
    }

    public static void main(String[] args) {
        System.out.println(new _477_totalHammingDistance().totalHammingDistance(new int[]{4, 14, 2}));
    }


}
